package api

import (
	"gitee.com/go-course/go11/vblog/apps/user"
	"gitee.com/go-course/go11/vblog/ioc"
	"github.com/gin-gonic/gin"
)

type Handler struct {
	svc user.Service
}

// 让他从Ioc中获取依赖的对象
func (h *Handler) Init() error {
	h.svc = ioc.GetController(user.AppName).(user.Service)
	return nil
}

func (h *Handler) Name() string {
	return user.AppName
}

func (h *Handler) Registry(r gin.IRouter) {
	// subrouter的前缀: "/vblog/api/v1/users"
	// /vblog/api/v1/users/login
	r.POST("/login", h.Login)
}

func init() {
	ioc.RegistryHttpApi(&Handler{})
}
